var gulp = require('gulp'),
	livereload = require('gulp-livereload'),
 	jsconcat = require('gulp-concat'),
 	uglify = require('gulp-uglify'),
 	cssmin = require('gulp-clean-css'),
 	htmlmin = require('gulp-htmlmin');


gulp.task('miniCss',function(){

	gulp.src('src/css/mz/*.css')
		.pipe(cssmin(/*{
            compatibility: 'ie7'
        }*/))
		.pipe(gulp.dest('dest/css/mz'))

});

// 任务
gulp.task('miniJs',function(){
	//gulp.src(['src/js/**/*.js','!src/js/lib/*.js'])
	gulp.src(['src/js/app/**/*.js'])
	//.pipe(jsconcat('miaozhen.js'))
	.pipe(uglify({
            //mangle: true,//类型：Boolean 默认：true 是否修改变量名
            mangle: {except: ['require' ,'exports' ,'module' ,'$','angular']},//排除混淆关键字
        	//compress: true,//类型：Boolean 默认：true 是否完全压缩
            //preserveComments: all //保留所有注释
        }))
	.pipe(gulp.dest('dest/js'));


});

gulp.task('miniHtml',function(){
	var options = {
        removeComments: true,//清除HTML注释
        collapseWhitespace: true,//压缩HTML
        collapseBooleanAttributes: false,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: false,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
        minifyJS: true,//压缩页面JS
        minifyCSS: true//压缩页面CSS
    };

	gulp.src('src/tpls/**/*.html')
	.pipe(htmlmin(options))
	.pipe(gulp.dest('dest/tpls'));

});


//监控任务
gulp.task('watchtask',function(){
	//启动livereload监听
	livereload.listen();

	gulp.watch('app/js/*.js',['miniJs'],function(event){
		console.log('File '+event.path+' is '+event.type + ', running tasks...');
	});
});


// 默认任务
gulp.task('default',['miniCss','miniJs','miniHtml'],function(){

});
